package com.yhsoft.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yhsoft.sys.controller.Response.SysContentOutVo;
import com.yhsoft.sys.controller.request.SysContentInVo;
import com.yhsoft.sys.entity.SysContent;
import com.yhsoft.sys.mapper.SysContentMapper;
import com.yhsoft.sys.service.ISysContentService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 平台内容配置 服务实现类
 * </p>
 *
 * @author yyyyyyyh
 * @since 2023-11-20
 */
@Service
public class SysContentServiceImpl extends ServiceImpl<SysContentMapper, SysContent> implements ISysContentService {

    @Override
    public String set(SysContentInVo inVo) {
        LambdaQueryWrapper<SysContent> wrapper =new LambdaQueryWrapper<>();
        SysContent sysContent = this.getBaseMapper().selectOne(wrapper);
        if(sysContent == null){
            SysContent sysContent1 = new SysContent();
            sysContent1.setFkCityNum(inVo.getFkCityNum());
            sysContent1.setNoticeBalance(inVo.getNoticeBalance());
            sysContent1.setCurrencyName(inVo.getCurrencyName());
            sysContent1.setIconUrl(inVo.getIconUrl());
            sysContent1.setDeleted(0);
            this.getBaseMapper().insert(sysContent1);
            return "success";
        }
        sysContent.setFkCityNum(inVo.getFkCityNum());
        sysContent.setNoticeBalance(inVo.getNoticeBalance());
        sysContent.setCurrencyName(inVo.getCurrencyName());
        sysContent.setIconUrl(inVo.getIconUrl());
        this.getBaseMapper().updateById(sysContent);
        return "success";
    }

    @Override
    public SysContentOutVo getSysContent() {
        SysContentOutVo outVo = new SysContentOutVo();
        LambdaQueryWrapper<SysContent> wrapper =new LambdaQueryWrapper<>();
        SysContent sysContent = this.getBaseMapper().selectOne(wrapper);
        BeanUtils.copyProperties(sysContent,outVo);
        return outVo;
    }
}
